/**
 * @param {number[][]} points
 * @return {number}
 */
// 时间复杂度n^2logn
var numberOfBoomerangs = function (points) {
    if (points.length <= 2) return 0
    // 两个for还想个锤子
    let ans = 0
    let distance;
    for (let i = 0; i < points.length; i++) {
        let j = 0
        distance = []
        while (j < points.length) {
            if (i !== j) {
                let d1 = (points[i][0] - points[j][0]) * (points[i][0] - points[j][0])
                let d2 = (points[i][1] - points[j][1]) * (points[i][1] - points[j][1])
                distance.push(d1 + d2)
            }
            j++
        }
        // 记录当前相同数字的个数
        distance.sort()
        let sameNum = 1
        for (let i = 0; i < distance.length; i++) {
            if (i !== distance.length - 1 && distance[i] == distance[i + 1]) {
                sameNum++
            } else {
                if (sameNum >= 2) ans += sameNum * (sameNum - 1)
                sameNum = 1
            }
        }
    }
    return ans
};
var numberOfBoomerangs1 = function (points) {
    if (points.length <= 2) return 0
    // 两个for还想个锤子
    // 方法没问题枚举+计数
    let ans = 0
    let map;
    for (let i = 0; i < points.length; i++) {
        let j = 0
        map = {}
        while (j < points.length) {
            if (i !== j) {
                let d1 = (points[i][0] - points[j][0]) * (points[i][0] - points[j][0])
                let d2 = (points[i][1] - points[j][1]) * (points[i][1] - points[j][1])
               if(map.hasOwnProperty(d1+d2)) map[d1+d2]++
               else map[d1+d2] = 1
            }
            j++
        }
        Object.keys(map).forEach(k => {
            if(map[k] >= 2) ans += map[k] * (map[k] - 1)
        })
    }
    return ans
}
console.log(numberOfBoomerangs1([[0, 0], [1, 0], [2, 0]]));